package com.sskj.xyft.message;

import com.sskj.xyft.BasePresenter;
import com.sskj.base.utils.GsonUtil;
import com.sskj.base.utils.RxUtils;
import com.sskj.xyft.api.Api;
import com.sskj.xyft.api.SimpleHttpObserver;
import com.sskj.xyft.message.data.OtherMessage;


/**
 * @author Hey
 * Create at  2019/03/21
 */
class MessagePresenter extends BasePresenter<MessageFragment> {

    public void getMessageList(String minID, boolean showLoading) {
        Api.getInstance().getMessageList()
                .compose(RxUtils.transform())
                .subscribe(new SimpleHttpObserver<String>(this, showLoading) {
                    @Override
                    public void onSuccess(String data) {
                        mView.setData(GsonUtil.GsonToBean(data, OtherMessage.class));
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.finishRefresh();
                    }
                });
    }

    public void getMessageListMore(String minID, boolean showLoading) {
        Api.getInstance().getMessageListMore(minID)
                .compose(RxUtils.transform())
                .subscribe(new SimpleHttpObserver<String>(this, showLoading) {
                    @Override
                    public void onSuccess(String data) {
                        mView.setData(GsonUtil.GsonToBean(data, OtherMessage.class));
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.finishRefresh();
                    }
                });
    }
}
